package com.datn.activity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import com.datn.DataAccess.FavouriteDatabaseAdapter;
import com.datn.DataAccess.UserDatabaseAdapter;
import com.datn.DataAccess.ImageAdapter;
import com.datn.DataAccess.SQLiteTest;
import com.datn.beans.FavouriteBean;
import com.datn.beans.UserBean;
import com.datn.utils.AlertCustom;
import com.datn.utils.DialogUtils;
import com.datn.utils.FileUtils;
import com.datn.utils.GPSUtils;
import com.datn.utils.HelloItemizedOverlay;
import com.datn.utils.NetworkUtils;
import com.datn.utils.PreferenceUtils;
import com.datn.utils.places.DirectionObject;
import com.datn.utils.places.JsonDirection;
import com.datn.utils.places.JsonPlace;
import com.datn.utils.places.Place;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.AlertDialog.Builder;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.OperationApplicationException;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class NearLocationActivity extends Activity   {
    
	ImageAdapter adapter;
	GridView gridview;
	Context mContext;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nearlocationview);
        mContext = this;
        PreferenceUtils.getInstance(this);
        gridview = (GridView) findViewById(R.id.gridviewNearLocation);
        adapter=new ImageAdapter(this);
        
        gridview.setAdapter(adapter);
       
        
        //registerForContextMenu(bt);
        
        //getResources().getString(R.string.API_KEY);
    }
    
    
   
  
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.main_menu, menu);
		return true;
	}


	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.btFavouriteMainMenu:
			processClickFavouriteMenu();			
			break;
		case R.id.itemRegisterMainMenu:
			processClickRegisterMenu();
			break;
		case R.id.itemRecentMainMenu:
			processClickRecentMenu();
			break;
		case R.id.itemSearchMainMenu:
			processClickSearchMenu();
			break;
		
		case R.id.itemAboutMainMenu:
			processClickAboutMenu();
			break;
		case R.id.itemHelpMainMenu:
			processClickHelpMenu();
			break;
			
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}
	
	
	
	
	private void processClickHelpMenu() {
		// TODO Auto-generated method stub
		DialogUtils.getInstance(this);
		DialogUtils.showCustomHelpDialog(R.layout.help_main_menu);
	}




	private void processClickAboutMenu() {
		// TODO Auto-generated method stub
		DialogUtils.getInstance(this);
		DialogUtils.showCustomAboutDialog(R.layout.about);
	}




	private void processClickSearchMenu() {
		// TODO Auto-generated method stub
		AlertDialog.Builder alert = new AlertDialog.Builder(this);

		alert.setTitle("Input address for search");
		//alert.setMessage("Message");

		// Set an EditText view to get user input 
		final EditText input = new EditText(this);
		input.setLines(1);
		alert.setView(input);

		
		alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int whichButton) {
		  String value = input.getText().toString();
		  // Do something with value!
		  PreferenceUtils.setSearchTypeAnyAddress(true);
		  PreferenceUtils.setModeOnlinẹ̣(true);
		  PreferenceUtils.setSearchTypeValue(value);
		  Intent intent=new Intent(mContext, ListPlaceActivity.class);
			
			startActivity(intent);
			finish();	
		  }
		});

		alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
		  public void onClick(DialogInterface dialog, int whichButton) {
		    // Canceled.
		  }
		});

		alert.show();
	}




	private void processClickRecentMenu() {
		// TODO Auto-generated method stub
		if (UserBean.isLogin){
			Intent intent = new Intent(this, RecentPlaceActivity.class);
			startActivity(intent);
			finish();
		}
		else {
			Intent intentLogin = new Intent(this, LoginActivity.class);
			startActivity(intentLogin);
			finish();
		}
	}




	public void processClickFavouriteMenu(){
		if (UserBean.isLogin){
			Intent intentFavorite = new Intent(this, FavouriteActivity.class);
			startActivity(intentFavorite);
			finish();
		}
		else{
			Intent intentLogin=new Intent(this, LoginActivity.class);
			startActivity(intentLogin);
			finish();
		}
	}
	
	
	
	public void processClickRegisterMenu(){
		Intent intentRegister=new Intent(this, RegisterActivity.class);
		startActivity(intentRegister);
		finish();
	}
	

/*
	@Override  
    public boolean onContextItemSelected(MenuItem item) {  
        if(item.getTitle()=="Action 1"){
        	AlertCustom.showAlert(this, "OK", "Action 1");
        }  
        else if(item.getTitle()=="Action 2"){
        	AlertCustom.showAlert(this, "OK", "Action 2");
        }  
        else {return false;}  
        return true;  
    }


	 @Override  
	    public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {  
	    super.onCreateContextMenu(menu, v, menuInfo);  
	        menu.setHeaderTitle("Context Menu");  
	        menu.add(0, v.getId(), 0, "Action 1");  
	        menu.add(0, v.getId(), 0, "Action 2");  
	    }  */
    
    
    
    

	



}